import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 键盘
from selenium.webdriver import Keys
# 等待事件
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# 鼠标
from selenium.webdriver.common.action_chains import ActionChains

driver=webdriver.Edge()
driver.maximize_window()
driver.get('http://10.59.9.12:7001/')
# 隐式等待 2
driver.implicitly_wait(1)
# 登录  鼠标操作
sbcz=driver.find_element(By.XPATH,'//a[@href="/home/login.html"]')
# 强制等待 1
time.sleep(3)
# 单击
ActionChains(driver).click(sbcz).perform()
# 双击
# ActionChains(driver).double_click(sbcz).click()

# 断言  会员登录
dy1=driver.find_element(By.CLASS_NAME,'reg-new').text
print(dy1)
time.sleep(3)
# 用户名  键盘操作
a=driver.find_element(By.NAME,'username')
a.send_keys("13811033962")
a.send_keys(Keys.ENTER)
time.sleep(3)
# 密码
driver.find_element(By.NAME,'password').send_keys("123456")
time.sleep(8)
# 登录按钮  显示等待
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="theForm"]/div[5]/a'))).click()
# driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
# time.sleep(6)
# 切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(3)
# 点击首页
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(3)
# JS操作 向下滑动800像素
driver.execute_script('window.scrollTo(0,800)')
time.sleep(5)
# 点击商品信息 商品详情
driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img').click()
time.sleep(20)
# yuansu=driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[5]/div[1]/a/img')
# print(yuansu.text)
# print(yuansu.is_displayed())
# print(yuansu.get_attribute('class'))
# # 立即购买
driver.find_element(By.ID,'buy-cart').click()
time.sleep(3)
# 确认收获地址
driver.find_element(By.XPATH,'//input[@class="radio-select-btn" or @name="address_id"]').click()
time.sleep(3)
# 下一步 确认支付下单成功
driver.find_element(By.CSS_SELECTOR,'.ask-btn').click()
time.sleep(3)
# 退出 浏览器事件：
driver.refresh()

